package com.example.mybatis.util;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.*;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@Slf4j
@MappedJdbcTypes(JdbcType.VARCHAR)
@MappedTypes({String.class})
public class EncHandle implements TypeHandler<String> {
//    @Override
//    public void setNonNullParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException {
//        System.out.println(s);
//        preparedStatement.setString(1,EncUtil.getMd5(s));
//    }
//
//    @Override
//    public String getNullableResult(ResultSet resultSet, String s) throws SQLException {
//        return null;
//    }
//
//    @Override
//    public String getNullableResult(ResultSet resultSet, int i) throws SQLException {
//        return null;
//    }
//
//    @Override
//    public String getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
//        return null;
//    }

    @SneakyThrows
    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException {
        log.info("原始数据为："+s);
        log.info("加密处理后的数据为："+EncUtil.getMd5(s));
        preparedStatement.setString(i,EncUtil.getMd5(s));
    }

    @Override
    public String getResult(ResultSet resultSet, String s) throws SQLException {
        return null;
    }

    @Override
    public String getResult(ResultSet resultSet, int i) throws SQLException {
        return null;
    }

    @Override
    public String getResult(CallableStatement callableStatement, int i) throws SQLException {
        return null;
    }
}
